package com.minelx.scriptbuilder.parse.matcher;

import com.minelx.scriptbuilder.script.attribute.value.ArithmeticSequence.Pair;
import com.minelx.sequence.IStringScanner;
import com.minelx.sequence.ReturnMatcher;
import com.minelx.sequence.ToResult;
import com.minelx.scriptbuilder.script.IVariable;
import com.minelx.scriptbuilder.script.attribute.value.Operators;

public class PairMatcher implements ReturnMatcher<Pair, IStringScanner> {

	private final ToResult<IVariable, IStringScanner> operatedValue;

	public PairMatcher(ToResult<IVariable, IStringScanner> operatedValue) {
		this.operatedValue = operatedValue;
	}

	@Override
	public boolean isMatch(IStringScanner scanner) {
		// FIXME 2021/3/18  wait for me!!!    ENUM as text
		return scanner.exists("+") ||
				scanner.exists("-") ||
				scanner.exists("*") ||
				scanner.exists("/") ||
				scanner.exists("|") ||
				scanner.exists("&")
				;
	}

	@Override
	public Pair onMatched(IStringScanner scanner) {
		return new Pair(Operators.of(String.valueOf(scanner.nextChar())), operatedValue.get(scanner));
	}
}
